﻿<%@ WebHandler Language="C#" Class="UploadImg" %>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.IO;
using System.Text;
using System.Collections;
using System.Net;
using System.Web.SessionState;
using System.Xml;
using BusinessLogic.ClassFactory;
using LitJson;
using System.Text.RegularExpressions;
using RichECMS;
using Common;

/// <summary>
/// UploadImg 的摘要说明
/// </summary>
public class UploadImg : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.AddHeader("Content-Type", "application/json; charset=UTF-8");
        Hashtable result = new Hashtable();
        string strsecid = HttpContext.Current.Request["secid"] ?? "null";
        List<Hashtable> hashlistsec = new List<Hashtable>();
        int thissecid = 0;

        if (IsNum(strsecid))
        {
            thissecid = int.Parse(strsecid);
        }
        else
        {
            result["success"] = false;
            result["msg"] = "参数输入错误";
            context.Response.Write(JsonMapper.ToJson(result));
            return;
        }

        try
        {
            using (SectionsFactory objFactory = new SectionsFactory())
            {
                int secid = 0;
                BusinessLogic.BusinessRules.Sections objSection = objFactory.CreatorBySql(" intParentID=" + thissecid + " ");
                if (objSection != null)
                {
                    for (int i = 0; i < objSection.Count; i++)
                    {
                        if (objSection.DataItem.intType == (int)Utility.STType.List)
                        {
                            Hashtable hastemp = new Hashtable();
                            hastemp["secid"] = objSection.DataItem.intSectionID;
                            hastemp["secname"] = objSection.DataItem.chvSTCName;
                            hastemp["secnameEN"] = objSection.DataItem.chvSTEName;
                            hashlistsec.Add(hastemp);
                        }
                        objSection.SelectRow(i + 1);
                    }
                }

                result["success"] = true;
                result["seclist"] = hashlistsec;
                result["msg"] = "";
                context.Response.Write(JsonMapper.ToJson(result));
                return;
            }
        }
        catch (Exception error)
        {
            error.Message.Replace("/r/n", "");
        }
    }
    /// <summary>
    /// 检测是否能转化为数字
    /// </summary>
    /// <param name="param">检测字符串</param>
    /// <returns>输出true/false</returns>
    public static bool IsNum(string param)
    {
        const string regEx = @"^[0-9]*$";
        if (Regex.IsMatch(param, regEx))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}